精选文章 >> 文件操作 >> 在JSP中写text文件 [查看别人的评论]

由 webmaster 发布于: 2001-01-20 16:18

Blueski编译


使用PrintWriter对象即可写Text文件。

请参考以下示例:

<%@ page import="java.io.*" %>
<%
String str = "print me";
//always give the path from root. This way it almost always works.
String nameOfTextFile = "/usr/anil/imp.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
//clean up
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>

现在,打开imp.txt加以查看,字符串"print me"应该已经写入。

还有另一种方法,使用IN16标记库的file tag,可参考http://sourceforge.net/project/?group_id=1282.
其示例的语法为:
<ext:file action="write|append|create|copy|move|delete|rename|read" from="<%= myfilename %>">



(全文完)

点这里对该文章发表评论

该文章总得分是 0 分,你认为它对你有帮助吗? [非常多](0) [有一些](0) [无帮助](0) [是灌水](0)

Copyright © 2001 - 2009 JSP001.com . All Rights Reserved